package ads.engenharia.ui;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JButton;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JInternalFrame;

import ads.engenharia.ui.curso.TelaCadastrarCurso;
import ads.engenharia.ui.curso.TelaConsultarCurso;
import ads.engenharia.ui.disciplina.TelaCadastrarDisciplina;
import ads.engenharia.ui.disciplina.TelaConsultarDisciplina;
import ads.engenharia.ui.professor.TelaCadastrarProfessor;
import ads.engenharia.ui.professor.TelaConsultarProfessor;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class TelaPrincipal extends JFrame {
    
    public static final int CURSO = 0;
    public static final int DISCIPLINA = 1;
    public static final int PROFESSOR = 2;
    
    private int indexPagina = 0;
    
    private TelaCadastrarProfessor telaCadastrarProfessor;

    /**
     * Creates new form TelaPrincipal
     */
    public TelaPrincipal() {
        initComponents();
        jPanel3.setVisible(false);
        
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        botaoMenuCurso = new javax.swing.JButton();
        botaoMenuDisciplina = new javax.swing.JButton();
        botaoMenuProfessor = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        botaoSubMenuCadastrar = new javax.swing.JButton();
        botaoSubMenuConsultar = new javax.swing.JButton();
        botaoSubMenuAssociar = new javax.swing.JButton();
        jDesktopPane1 = new javax.swing.JDesktopPane();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("EduInfo");
        setAlwaysOnTop(true);
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        botaoMenuCurso.setText("Curso");
        botaoMenuCurso.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoMenuCursoActionPerformed(evt);
            }
        });

        botaoMenuDisciplina.setText("Disciplina");
        botaoMenuDisciplina.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoMenuDisciplinaActionPerformed(evt);
            }
        });

        botaoMenuProfessor.setText("Professor");
        botaoMenuProfessor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoMenuProfessorActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(botaoMenuCurso, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(botaoMenuDisciplina, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(botaoMenuProfessor, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(246, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(botaoMenuCurso, javax.swing.GroupLayout.DEFAULT_SIZE, 41, Short.MAX_VALUE)
                    .addComponent(botaoMenuDisciplina, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(botaoMenuProfessor, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        botaoSubMenuCadastrar.setText("Cadastrar");
        botaoSubMenuCadastrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoSubMenuCadastrarActionPerformed(evt);
            }
        });

        botaoSubMenuConsultar.setText("Consultar");
        botaoSubMenuConsultar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoSubMenuConsultarActionPerformed(evt);
            }
        });

        botaoSubMenuAssociar.setText("Associar");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(botaoSubMenuConsultar))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(botaoSubMenuCadastrar)
                            .addComponent(botaoSubMenuAssociar, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(botaoSubMenuCadastrar)
                .addGap(27, 27, 27)
                .addComponent(botaoSubMenuConsultar)
                .addGap(26, 26, 26)
                .addComponent(botaoSubMenuAssociar)
                .addContainerGap(181, Short.MAX_VALUE))
        );

        jDesktopPane1.setBackground(new java.awt.Color(240, 240, 240));

        javax.swing.GroupLayout jDesktopPane1Layout = new javax.swing.GroupLayout(jDesktopPane1);
        jDesktopPane1.setLayout(jDesktopPane1Layout);
        jDesktopPane1Layout.setHorizontalGroup(
            jDesktopPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );
        jDesktopPane1Layout.setVerticalGroup(
            jDesktopPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jDesktopPane1))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jDesktopPane1)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>                        

    private void botaoMenuCursoActionPerformed(java.awt.event.ActionEvent evt) {                                               
        // TODO add your handling code here:
        jPanel3.setVisible(true);
        indexPagina = CURSO;
        botaoTelaConsultar();
    }                                              

    private void botaoSubMenuCadastrarActionPerformed(java.awt.event.ActionEvent evt) {                                                      
        // TODO add your handling code here:
        botaoTelaCadastrar();
    }                                                     

    private void botaoMenuProfessorActionPerformed(java.awt.event.ActionEvent evt) {                                                   
        // TODO add your handling code here:
        jPanel3.setVisible(true);
        indexPagina = PROFESSOR;
        botaoTelaConsultar();
        
    }                                                  

    private void botaoSubMenuConsultarActionPerformed(java.awt.event.ActionEvent evt) {                                                      
        // TODO add your handling code here:
        botaoTelaConsultar();
    }                                                     

    private void botaoMenuDisciplinaActionPerformed(java.awt.event.ActionEvent evt) {                                                    
        // TODO add your handling code here:
        jPanel3.setVisible(true);
        indexPagina = DISCIPLINA;
        botaoTelaConsultar();
    }                                                   

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(TelaPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(TelaPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(TelaPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(TelaPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new TelaPrincipal().setVisible(true);
            }
        });
    }
    
    
    public void abrirTelas(JInternalFrame frame) {
        frame.setVisible(true);
        fecharTelas();
        jDesktopPane1.add(frame);
    }
    
    
    public void fecharTelas() {
        for (JInternalFrame frame : jDesktopPane1.getAllFrames()) {
            frame.dispose();
        }
    }
    
   
    private void botaoTelaCadastrar() {
        
        switch (indexPagina) {
            case 0:
                TelaCadastrarCurso telaCadastrarCurso = new TelaCadastrarCurso();
                abrirTelas(telaCadastrarCurso);
                break;
            case 1:
                TelaCadastrarDisciplina telaCadastrarDisciplina = new TelaCadastrarDisciplina();
                abrirTelas(telaCadastrarDisciplina);
                break;
            case 2:
                TelaCadastrarProfessor telaCadastrarProfessor = new TelaCadastrarProfessor();
                abrirTelas(telaCadastrarProfessor);
                break;
        }
        
    }
    
    
    private void botaoTelaConsultar() {
        
        switch (indexPagina) {
            case 0:
                TelaConsultarCurso telaConsultarCurso = new TelaConsultarCurso(this);
                abrirTelas(telaConsultarCurso);
                break;
            case 1:
                TelaConsultarDisciplina telaConsultarDisciplina = new TelaConsultarDisciplina(this);
                abrirTelas(telaConsultarDisciplina);
                break;
            case 2:
                TelaConsultarProfessor telaConsultarProfessor = new TelaConsultarProfessor(this);
                abrirTelas(telaConsultarProfessor);
                break;
        }
        
    }
    

    // Variables declaration - do not modify                     
    private javax.swing.JButton botaoMenuCurso;
    private javax.swing.JButton botaoMenuDisciplina;
    private javax.swing.JButton botaoMenuProfessor;
    private javax.swing.JButton botaoSubMenuAssociar;
    private javax.swing.JButton botaoSubMenuCadastrar;
    private javax.swing.JButton botaoSubMenuConsultar;
    private javax.swing.JDesktopPane jDesktopPane1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    // End of variables declaration     
}
